#include "SipB2BSession.hpp"

#include "SipGDService.hpp"

namespace wtsip{


CSipB2BSession::CSipB2BSession(CSipGDService& srv, CSipSessionBase& caller, CSipSessionBase& callee):
m_service(srv), m_caller(caller), m_callee(callee), m_destroyCounter(2)
{
    caller.registerHandle(this);
    callee.registerHandle(this);
}


CSipB2BSession::~CSipB2BSession()
{
    //m_caller.unregisterHandle(this);
    //m_callee.unregisterHandle(this);
    /*if (m_handle){
        m_handle->onDestroy(*this);
    }*/
}


bool CSipB2BSession::destroy(){
    m_destroyCounter--;
    if (0 == m_destroyCounter){
        m_service.destroyB2bSession(this);
    }
    return true;
}


//bool CSipB2BSession::registerB2BHandle(CSipB2BSessionHandle* handle){
//    m_handle = handle;
//    return true;
//}
//
//
//bool CSipB2BSession::unregisterB2BHandle(){
//    m_handle = NULL;
//    return true;
//}



//bool CSipB2BSession::B2BRequest(SipMessage& request){
//    bool rt = false;
//    if (m_b2bSession && request.isRequest()){
//        m_b2bSession->onB2BRequest(request);
//        rt = true;
//    }
//    return rt;
//}
//
//
//bool CSipB2BSession::B2BResponse(SipMessage& response){
//    bool rt = false;
//    if (m_b2bSession && response.isResponse())
//    {
//        std::map<resip::Data, resip::Data>::iterator it;
//        const resip::Data& id = response.getTransactionId();
//        it = m_MessagesMap.find(id);
//        if (it != m_MessagesMap.end())
//        {
//            resip::Data& nId = it->second;
//            m_b2bSession->onB2BResponse(nId, response);
//            if (response.header(h_StatusLine).responseCode()/100 == 2)
//            {
//                m_MessagesMap.erase(it);
//            }
//            rt = true;
//        }
//    }
//    return rt;
//}


}//namespace


